﻿var BaseFramework = (function (_d, _e, _w) {
    var configs = {}, services = {}, constants = {};

    try {
        $.getJSON(_d, function (data) {
            if (Object.hasOwnProperty.call(data, "configs") && Object.hasOwnProperty.call(data, "services") && Object.hasOwnProperty.call(data, "constants")) {
                $.extend(configs, data.configs);
                $.extend(services, data.services);
                $.extend(constants, data.constants);
            }
            else {
                throw ("the configs init error");
            }

            $(configs["scripts"]).each(function (i, n) {
                _e.load(n, function () {
                    Object.hasOwnProperty.call(_w, "log") ? log.info("load scripts" + ":" + n + " success") : function () { return; };
                });
            });

            $(configs["styles"]).each(function (i, n) {
                _e.load(n, function () {
                    Object.hasOwnProperty.call(_w, "log") ? log.info("load styles" + ":" + n + " success") : function () { return; };
                });
            });

        });
    } catch (e) {
        Object.hasOwnProperty.call(_w, "log") ? log.error("ConfigManager" + ":" + e.description) : function () { return; };
    }

    return {
        getConstant: function (_k) {
            try {
                if (Object.hasOwnProperty.call(constants, _k)) {
                    return constants[_k.toString()];
                }
                else {
                    throw ("the constant you need is not existing!");
                }
            } catch (e) {
                Object.hasOwnProperty.call(_w, "log") ? log.error("getConstant" + ":" + e.description) : function () { return; };
            }
        },
        setConstant: function (_k, _v) {
            try {
                if (Object.hasOwnProperty.call(constants, _k)) {
                    if (_v === undefined) {
                        throw ("the value can't is underfined!");
                    }
                    else if (typeof _v == "function") {
                        throw ("the value can't is function!");
                    }
                    constants[_k.toString()] = _v;
                }
                else {
                    throw ("the constant you need is not existing!");
                }
            } catch (e) {
                Object.hasOwnProperty.call(_w, "log") ? log.error("setConstant" + ":" + e.description) : function () { return; };
            }
        },
        getConfig: function (_k) {
            try {
                if (Object.hasOwnProperty.call(configs, _k)) {
                    return configs[_k.toString()];
                }
                else {
                    throw ("the constant you need is not existing!");
                }
            } catch (e) {
                Object.hasOwnProperty.call(_w, "log") ? log.error("getConfig" + ":" + e.description) : function () { return; };
            }
        }
    };
})("../Config/FrameworkConfig.cf", easyloader, window);